package controller;

import java.sql.Time;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.inject.Inject;

import dao.TimeCardDao;
import entity.Contractor;
import entity.TimeCard;
@Stateless
public class TimeCardController {
	@Inject
	TimeCardDao timeCardDao;
	public TimeCard RegisterTimeCard(Date date, Time start, Time end,Contractor employee){
		return timeCardDao.CreateTimeCard(date, start, end,employee);
	}
	public List<TimeCard> ListOfTimeCards(Contractor employee){
		return timeCardDao.listTime(employee);
	}
	public int deleteTimeCard(TimeCard card){
		return timeCardDao.deleteTimeCard(card);
	}
	public int checkTimeCard(TimeCard card,Contractor employee){
		List<TimeCard> allCard=ListOfTimeCards(employee);
		for(int i=0;i<allCard.size();i++){
			if(allCard.get(i).getDate().compareTo(card.getDate())==0){
				//problemi
				if(!(allCard.get(i).getStart().before(card.getStart())&&allCard.get(i).getEnd().before(card.getStart()))&&!(allCard.get(i).getStart().after(card.getEnd()))){
						//(allCard.get(i).getStart().before(card.getStart())&&allCard.get(i).getEnd().after(card.getStart()))||(allCard.get(i).getStart().before(card.getEnd())&&(allCard.get(i).getEnd().before(card.getEnd())||allCard.get(i).getEnd().after(card.getEnd())))){
					
					/*DateFormat df = new SimpleDateFormat("HH:mm");
					System.out.println("allcard"+df.format(allCard.get(i).getStart())+" " +df.format(allCard.get(i).getEnd()));*/
					return 0;
					
				}
			}
		}
		return 1;
	}
}
